import * as React from "react";
import { lazy } from "react";
import { createBrowserRouter, Navigate } from "react-router-dom";
import Home from "@/pages/home";
import Layout from "@/layout";
import NotFound from "@/components/NotFound";
import Header from "@/components/Header";
import AgentPage from '@/pages/Agent'
import { authLoader} from './loader'
import Profile from '@/pages/Profile'
import PromotionPage from '@/pages/Promo'
const Game = lazy(() => import("../pages/games"));

// 使用了lazy加载的路由 必须搭配Suspense使用
// 路由鉴权 :1使用高阶组件包裹页面(复用差),在 根页面 中监听路径(闪屏),3:使用loader鉴权 loader加载器在路由加载前提供数据 v6 

const router = createBrowserRouter([
  {
    path: "/",
    element: <Layout />,
    children: [
      {  element:<Navigate to="/home" />, index: true },
      { path: "/home", element:<Home />, index: true },
      {
        path: "/Game",
        element: (
          <React.Suspense fallback="失败了">
            <Game />
          </React.Suspense>
        ),
        loader: authLoader,
      },
      {  path: "/profile",element: <Profile/>,loader: authLoader,},
      {  path: "/agent",element: <AgentPage/>,loader: authLoader,},
      {  path: "/Promo",element: <PromotionPage/>,},
      
      { path: "*", element: <NotFound /> },
    ],
    
  },
  
]);

export default router;
